﻿


using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using System.Linq;
using System.Security.Claims;

using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authentication;
using Lucene.Net.Analysis;
using System.Collections.Generic;

using Ccteg.Common;
using Ccteg.DB;

namespace Cctegaq.Api.Controllers
{
    /// <summary>
    /// 基础主数据
    /// </summary>
    [Route("api/[controller]/[action]")]
    //[ApiExplorerSettings(GroupName = "jcsj")]
    [ApiController]
    public class ManagementDataController : ControllerBase
    {
        private readonly AppAuthenticationSettings _appSettings;
        private readonly MySqlDbContext _dbContext;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="appSettings"></param>
        public ManagementDataController(IOptions<AppAuthenticationSettings> appSettings, MySqlDbContext dbContext)
        {
            _appSettings = appSettings.Value;
            _dbContext = dbContext;
        }


        /// <summary>
        /// 基础数据一级类别查看
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ResponseModel<List<Management_data>> GetClass()
        {
            var res = new ResponseModel<List<Management_data>>();
            using (_dbContext)
            {

                var query = _dbContext.Management_data.Where(x => x.ParentId == 0 && x.Deleted == false).OrderBy(x => x.NumOrder).ThenBy(x => x.Id).ToList();
                res.Data = query;
                return res;
            }
        }
        /// <summary>
        /// 获取分类下基础数据
        /// </summary>
        /// <param name="ParentCode">编码</param>
        /// <returns></returns>
        [HttpGet]

        public ResponseModel<List<Management_data>> GetItemList(string ParentCode)
        {


            var res = new ResponseModel<List<Management_data>>();
            using (_dbContext)
            {

                var query = _dbContext.Management_data.Where(x => x.ParentCode == ParentCode && x.ParentId > 0 && x.Deleted == false).OrderBy(x => x.NumOrder).ToList();
                res.Data = query;
                return res;
            }
        }

        /// <summary>
        /// 获取企业信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]

        public ResponseModel<List<ent_baseinfo>> GetEnterpriseInfoList()
        {
            var res = new ResponseModel<List<ent_baseinfo>>();
            using (_dbContext)
            {
                var query = _dbContext.Ent_Baseinfo.Where(x => x.OnState == "启用" && x.Deleted == false).OrderBy(x => x.Sort).ToList();
                res.Data = query;
                return res;
            }
        }
    }
}